package elements;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RadialGradientPaint;
import java.util.ArrayList;

import utils.ImageUtil;

public class Coin extends Element {
	ArrayList<Integer> acceptColor = new ArrayList<Integer>();
	ArrayList<Integer> acceptDirection = new ArrayList<Integer>();
	public Coin(int x,int y, int color,int direction,int actType){
		super(x, y, color, direction,actType);
		this.type =Element.COIN;
		
	}
	public void accept(int color,int direction){
		acceptColor.add(color);
		acceptDirection.add(direction);
	}
	
	public boolean isAccept(){
		boolean flag = false;
		for(int i =0;i<acceptDirection.size()-1;i++){
			if((Math.abs(acceptDirection.get(i).intValue()-acceptDirection.get(i+1).intValue())!=4&&(Math.abs(acceptDirection.get(i).intValue()-acceptDirection.get(i+1).intValue())!=0)))return flag;
		}
		int mixcolor =0;
		for(int i =0;i<acceptColor.size();i++){
			mixcolor|=acceptColor.get(i).intValue();
		}
		if(mixcolor==color)flag=true;
		return flag;
	}
	public boolean canGo(int inDirection){
		return true;
	}
	public void draw(Graphics2D g){
		Color oldColor = g.getColor();
		if(ImageUtil.currentStyle==1){
			g.setColor(new Color(color));
			if(isAccept()){
				g.fillOval(x-width/2, y-height/2,width,height);
			}else{
				g.drawOval(x-width/2, y-height/2,width,height);
			}
		}else{
			if(isAccept()){
				image= ImageUtil.getImage("coin"+color+"-1");
			}else{
				image= ImageUtil.getImage("coin"+color+"-2");
			}
			g.drawImage(image, x-width/2, y-height/2,null);
		}
		g.setColor(oldColor);
	}
}
